#ifndef _MY_MATH
#define _MY_MATH

#include <iostream>
#include <cmath>

double derivative(double (*)(double), double);
double integral(double (*)(double), double, double);

double derivative(double (*fun)(double), double x0)
{
    return ((*fun)(x0 + LIMIT_ZERO) - (*fun)(x0 - LIMIT_ZERO)) / (2 * LIMIT_ZERO);
}

double integral(double (*fun)(double), double lb, double ub)
{
    double ptr = lb;
    double result = 0;
    while (ub - ptr >= LIMIT_ZERO * 0.1)
    {
        result += 0.5 * (LIMIT_ZERO) * ((*fun)(ptr) + (*fun)(ptr + LIMIT_ZERO));
        ptr += LIMIT_ZERO;
    }
    if (fabs(result) <= LIMIT_ZERO)
    {
        result = 0;
    }
    return result;
}

#endif